{include file="header/index" /}
<div class="newContentBox">
	<div class="fixedFather">
			<div class="fix">
					编辑菜单
					<span class="newNotice"><span class="newtext">*</span>为必填项</span>
					<div class="newFixBtnBox">
							<button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</button>
					</div>
			</div>
	</div>
	<form action="" class="layui-form newListPart ">
		<input type="hidden" name="id" value="{$data.id}">
		<div class="newPart">
				<div class="newTitle">
						<i class="fa fa-address-book allColor icon"></i>	基本信息
				</div>
		</div>
		<div class="newContent">
			<div class="layui-form-item cover_layui_f_i">
				<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 菜单名称</label>
				<div class="layui-input-block cover_layui_i_b">
					<input type="text" name="title" value="{$data.title}" required  lay-verify="required"  autocomplete="off" class="layui-input">
				</div>	
			</div>
			<div class="layui-form-item cover_layui_f_i">
				<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 菜单父级</label>
				<div class="layui-input-block cover_layui_i_b">
					<select name="pid" id="pid">
						<option value="0" {if condition="$data['pid'] eq 0"}selected{/if}>顶级菜单</option>
						{foreach $node as $key => $val}
						<option value="{$val.id}" {if condition="$val['id'] eq $data.pid"}selected{/if}>{$val.lefthtml}{$val.title}</option>
						{/foreach}							
					</select>
				</div>
			</div>
			<div class="layui-form-item cover_layui_f_i">
				<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 节点</label>
				<div class="layui-input-block cover_layui_i_b">
					<input type="text" name="url" id="url" value="{$data.url}" placeholder="模块/控制器/方法" required  lay-verify="required"  autocomplete="off" class="layui-input">
					<div>如：operation/user/adduser (顶级节点添加“#”即可)</div>
				</div>	
			</div>
			<div class="layui-form-item cover_layui_f_i">
				<label class="layui-form-label cover_layui_f_l"> css样式</label>
				<div class="layui-input-block cover_layui_i_b">
					<input type="text" name="css" id="css" placeholder="输入CSS样式" value="{$data.css}" autocomplete="off" class="layui-input">
					<span class="lookIcon spanPo">
						<a style="color: #1cafff;cursor: pointer;" href="http://fontawesome.dashgame.com/" target="_blank" target="_blank">
						<img src="__IMG__/icon17.png" width="12px" alt="">图标
						</a>
					</span>
					<div>如：如：fa fa-user</div>
				</div>	
			</div>
			<div class="layui-form-item cover_layui_f_i">
					<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span>显示在菜单栏</label>
					<div class="layui-input-block cover_layui_i_b">
						<input type="radio"  name="menutitle"  value="0"  lay-skin="primary" title="否" {if condition="$data['menutitle'] eq 0"}checked{/if}>
						<input type="radio" name="menutitle"  value="1"  lay-skin="primary" title="是" {if condition="$data['menutitle'] eq 1"}checked{/if}>
					</div>
			</div>
			<div class="layui-form-item cover_layui_f_i">
				<label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 排序</label>
				<div class="layui-input-block cover_layui_i_b">
					<input type="text" name="sort" id="sort" value="{$data.sort}" placeholder="输入排序" required  lay-verify="required"  autocomplete="off" class="layui-input">
				</div>	
			</div>
		</div>
		<div class="layui-form-item ">
					<div class="layui-input-block cover_layui_i_b">
						<button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo" >保存</button>
						<button type="reset" class="layui-btn newBtnDefault" >重置</button>
					</div>
		</div>
	</form>
</div>
	
<script>
	var layer = layui.layer,
		element = layui.element,
		laydate = layui.laydate,
		laypage = layui.laypage,
		form = layui.form,
		upload = layui.upload,
		layedit = layui.layedit;
form.render();



	/**
	 * 修改系统菜单栏
	 */
	// function updateMenu(){
	// 	var title = $("input[name='title']").val();
	// 	var url = $("input[name='url']").val();
	// 	var sort = $("input[name='sort']").val();
	// 	var id = $("input[name='id']").val();
	// 	var css = $("input[name='css']").val();
 //        var pid = $("#pid").val();
	// 	if($('#status').is(':checked')) {
	// 	    var status = 1;
	// 	}else{
 //                    var status = 0;
	// 	}
 //        if($("#menutitle").is(':checked')) {
	// 	    var menutitle = 1;
	// 	}else{
 //                    var menutitle = 0;
	// 	}
 //        var selfId = "{$data.id}";
 //        if(selfId == pid){
 //            layer.msg('上级菜单不能是自己', {icon: 2,time: 2000});
 //            return;
 //        }
	// 	$.post("{:url('Menu/ModifyTheSort')}",{title:title,url:url,sort:sort,id:id,status:status,css:css,menutitle:menutitle,pid:pid},function(e){
	// 		if(e.code == '1'){
	// 			layer.msg(e.msg, {icon: 1,time: 2000},function(){window.location.href="{:url('Authgroup/index')}?type=3"});
	// 		}else{
	// 			layer.msg(e.msg, {icon: 2,time: 2000});
	// 		}
	// 	},'json');
	// }
	//重置
	function reset() {
		top.layer.confirm('你确定要重置吗?', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$("#edit_rule")[0].reset();
			top.layer.msg('重置成功', {
				icon: 1
			});
		});
	}
	//提交表单
    var flag = false;
      form.on('submit(formDemo)', function(data){
      	if($('#status').is(':checked')) {
		    var status = 1;
		}else{
                    var status = 0;
		}
        if($("#menutitle").is(':checked')) {
		    var menutitle = 1;
		}else{
            var menutitle = 0;
		}
		var pid = $("#pid").val();
        var selfId = "{$data.id}";
        if(selfId == pid){
            layer.msg('上级菜单不能是自己', {icon: 2,time: 2000});
            return;
        }

        if(flag){
        return false;
        }
        flag = true;
        delete data.field.file //true
        console.log('数组',data.field);
        $.post("{:url('Menu/ModifyTheSort')}",data.field,function(e){
          if(e.code == 1){
            top.layer.msg(e.msg, {
              icon: 1,
              time: 2000
            },function(){
              top.layer.close();
              history.go(-1); 
            });
          }else{
            top.layer.msg(e.msg, {
              icon: 0,
              time: 2000
            });
          }
          flag = false;
        },'json');
        return false;
      });



</script>
